package com.example.user.controller;


import annotation.RequireRoles;
import com.example.user.service.RoleServiceImpl;
import entity.PageParam;
import entity.Rsp;
import entity.Role;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 模块接口
 */

@RestController
@Api(value = " 模块接口",description=" 模块接口")
public class RoleController {

    private static final Logger log = LoggerFactory.getLogger(RoleController.class);

    @Autowired
    RoleServiceImpl roleService;



    @PostMapping("/searchSomeRoleByPage")
    @RequireRoles(roles = {"admin","super_admin"},index = 2)
    @ApiOperation("查询所有 支持 多条件 分页 排序 查询")
    public Rsp searchSomeByPage(@RequestBody PageParam<Role> rolePageParam,
                                @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        log.info("userId:{}",userId);
        log.info("roleId:{}",roleSign);

        return Rsp.success(roleService.searchSomeByPage(rolePageParam));
    }


    @RequireRoles(roles = {"super_admin","admin"},index = 2)
    @PostMapping("/addOneRole")
    @ApiOperation("添加单个")
    public Rsp addOne(@RequestBody @Valid Role role, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        role.setCreateUserId(userId);
        return roleService.addOne(role);
    }


    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteOneRoleTrue")
    @ApiOperation("通过ID物理删除")
    public Rsp deleteOneRoleTrue(@RequestBody Role role, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){

        return roleService.deleteOneTrue(role.getId());
    }

    @RequireRoles(roles = {"super_admin","admin"},index = 2)
    @PostMapping("/updateRole")
    @ApiOperation("动态修改")
    public Rsp updateRole(@RequestBody Role role, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){


        role.setUpdateUserId(userId);
        return roleService.update(role);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteRoleLogical")
    @ApiOperation("通过ID逻辑删除")
    public Rsp deleteRoleLogical(@RequestBody Role role, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return roleService.deleteLogical(role);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/recoverRoleLogical")
    @ApiOperation("逻辑恢复")
    public Rsp recoverRoleLogical(@RequestBody Role role, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return roleService.recoverLogical(role);
    }


    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteBatchRoleTrue")
    @ApiOperation("批量物理删除")
    public Rsp deleteBatchRoleTrue(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return roleService.deleteBatchTrue(ids);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteBatchRoleLogical")
    @ApiOperation("批量逻辑删除")
    public Rsp deleteBatchRoleLogical(@RequestBody List<String> ids, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return roleService.deleteBatchLogical(ids);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteSomeRoleLogicalByCondition")
    @ApiOperation("条件逻辑删除")
    public Rsp deleteSomeRoleLogicalByCondition(@RequestBody Role role, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return roleService.deleteSomeLogicalByCondition(role);
    }

    @RequireRoles(roles = {"super_admin"},index = 2)
    @PostMapping("/deleteSomeRoleTrueByCondition")
    @ApiOperation("条件物理删除")
    public Rsp deleteSomeRoleTrueByCondition(@RequestBody Role role, @RequestHeader(value = "userId") String userId, @RequestHeader(value = "roleSign") String roleSign){



        return roleService.deleteSomeTrueByCondition(role);
    }


}
